﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WarehouseManagement.BusinessLogic.BC;
using WarehouseManagement.ViewModels.PO;

namespace WarehouseManagement.Presenters.PO
{
    public class ViewSupplierDebtPresenter : BasePresenter<IViewSupplierDebtViewModel>
    {
        private DebitBC _debitBC;

        public ViewSupplierDebtPresenter()
        {
            _debitBC = new DebitBC();
        }

        protected override void WireupEventHandles()
        {

        }

        public void LoadSupplierDebtViewData()
        {
            var data = _debitBC.GetMerchandiseDebitInfo(Model.FromDate, Model.ToDate);
            Model.DebitItems = data.ToList();

        }

        public decimal GetTotalReceiveMoneyOf(string documentNumber, DateTime fromDate, DateTime toDate, DateTime debtDate)
        {
            POBC poBC = new POBC();
            var val = poBC.GetTotalReceivedMoney(documentNumber, fromDate, toDate, debtDate);
            poBC = null;
            return val;

        }

        public DateTime GetDebitUntilDate(int supplierId, DateTime untilDate)
        {
            var obj = _debitBC.GetLastPeriodDebtOfSupplier(supplierId, untilDate);
            if (obj == null)
            {
                return DateTime.Now;
            }
            return obj.FromDate;
        }

        public decimal GetDebitUntilToday(int supplierId)
        {
            var obj = _debitBC.GetLastPeriodDebtOfSupplier(supplierId, DateTime.Now);
            if (obj == null)
            {
                return 0;
            }
            return obj.Debt;
        }
    }
}
